//
//  HongbaoViewController.m
//  SelfDriving
//
//  Created by apple on 16/2/6.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "HongbaoViewController.h"
#import "BusinessService+User.h"
#import "SVProgressHUD.h"
#import "HongbaoDViewController.h"
@interface HongbaoViewController ()
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UIImageView *head_img;
@property (weak, nonatomic) IBOutlet UIButton *chai_btn;
@property (weak, nonatomic) IBOutlet UIButton *shouqi_btn;
@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet UILabel *titlelable;
@property (weak, nonatomic) IBOutlet UILabel *typelable;

@end

@implementation HongbaoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _chai_btn.hidden = YES;
    _bgView.frame = self.view.frame;
    _bgView.layer.opacity = 0.8;
    _head_img.layer.cornerRadius = _head_img.frame.size.width/2;
    _head_img.layer.masksToBounds = YES;
    _chai_btn.layer.cornerRadius = _chai_btn.frame.size.width/2;
    _dic = [AppDelegate shareDelegate].hbdic;
    [ValidateHelper setImage:[_dic objectForKey:@"headsmall"] img:_head_img istoux:YES];
     _name.text = [_dic objectForKey:@"nickname"];
    if ([[_dic objectForKey:@"type"] intValue]==2) {
        _typelable.hidden = YES;
    }
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setObject:[_dic objectForKey:@"id"] forKey:@"hongbao_id"];
    
    //xhw2018-1-25改bug15354
//    [[BusinessService shareInstance]has_qianghongbao:dic success:^(id result) {
//        NSMutableDictionary *dic = result;
//        if ([[dic objectForKey:@"data"] intValue] == 1) {//0 未抢 1 已抢
//            _titlelable.text = @"手慢了，红包派完了";
//        }else{
//            _titlelable.text = [_dic objectForKey:@"title"];
//            _chai_btn.hidden = NO;
//        }
//    } failure:^(id result) {
//
//    }];
    
    [[BusinessService shareInstance]has_qianghongbao:dic success:^(id result) {
        NSMutableDictionary *dic = result;
        if ([[dic objectForKey:@"data"] intValue] == 1) {//0 未抢 1 已抢
            _titlelable.text = @"你已经抢过该红包";  //xhw2018-1-25
        }else{
            NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
            [dic setObject:[_dic objectForKey:@"id"] forKey:@"hongbao_id"];
            [[BusinessService shareInstance]qiang_hongbao:dic success:^(id result) {
                NSMutableDictionary *dic1 = result;
                if ([[dic1 objectForKey:@"data"] floatValue] == 0)  {
                    _titlelable.text = @"手慢了，红包派完了";
                }
                else  {
                    _titlelable.text = [_dic objectForKey:@"title"];
                    _chai_btn.hidden = NO;
                }
                
            } failure:^(id result) {
                [SVProgressHUD showErrorWithStatus:result];
            }];
        }
    } failure:^(id result) {

    }];
    
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
- (IBAction)backAction:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)chaiAction:(UIButton *)sender {

    UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"MS"
                                                                 bundle:[NSBundle mainBundle]];
    HongbaoDViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"HongbaoDViewController"];
    searchResultDetailController.presentVC = self;
    [self presentViewController:searchResultDetailController animated:YES completion:nil];
    /* xhw2018-1-25改
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setObject:[_dic objectForKey:@"id"] forKey:@"hongbao_id"];
    [[BusinessService shareInstance]qiang_hongbao:dic success:^(id result) {
        
        UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"MS"
                                                                     bundle:[NSBundle mainBundle]];
        HongbaoDViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"HongbaoDViewController"];
        [self presentViewController:searchResultDetailController animated:YES completion:nil];
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:result];
    }];
     */
}
#pragma mark 红包详情
- (IBAction)hongbaoDaction:(UIButton *)sender {
    UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"MS"
                                                                 bundle:[NSBundle mainBundle]];
    HongbaoDViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"HongbaoDViewController"];
    [self presentViewController:searchResultDetailController animated:YES completion:nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
